using System;
using System.Windows.Forms;
using HogoLogic.HgFileSystem;

namespace FileSystemView
{
	partial class DirectoryView : UserControl
	{
		readonly DirectoryTreeNodeVisualizer visualizer = new DirectoryTreeNodeVisualizer();
		
		public event EventHandler OnSelectedDirectoryChanged;
		
		public DirectoryView()
		{
			InitializeComponent();
		}
		
		public void Open(HgDirectoryInfo directoryInfo)
		{
			innerTreeView.Nodes.Clear();
			innerTreeView.Nodes.Add(visualizer.MakeTreeNode(directoryInfo));
		}

		public HgDirectoryInfo SelectedDirectory
		{
			get
			{
				return visualizer.GetDirectoryForTreeNode(
					innerTreeView.SelectedNode);
					
			}
		}

		private void innerTreeView_AfterSelect(object sender, TreeViewEventArgs e)
		{
			if (OnSelectedDirectoryChanged != null)
				OnSelectedDirectoryChanged(sender, new EventArgs());
		}
	}
}